<template>
  <div class="admin-body">
    <el-row>
      <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>轮播图管理</el-breadcrumb-item>
      </el-breadcrumb>
    </el-row>
    <el-row class="main">
      <el-row :gutter="10" style="min-heightotalt: 40px">
        <my-upload ref="my_upload" @change="submitAdd" @changedel="submitDel" multiple ></my-upload>
      </el-row>

    </el-row>
  </div>
</template>

<script>
  import MyUpload from '../../components/MyUpload'

  export default {
    name: "Rotation",
    components:{
      MyUpload
    },
    mounted() {
      if(!this.$store.state.login.in){
        this.$router.push({ name: "login", params: { userId: 123 }})
      }
      this.getStart()
    },
    data() {
      return {
        addUrl:[],
        listData:[]
      }
    },

    methods: {
      //获取
      getStart() {
        let thi = this
        const por = {
        }
        thi.mySelectAll('showList', por).then(function (value) {
          thi.listData=value.data
          var imgdata = []
          value.data.forEach((value,index)=>{
            imgdata.push(value.url)
            })
          thi.$nextTick(function () {
            thi.$refs.my_upload.medioData = imgdata
          })
        })
      },
      submitDel(index){
        this.mySubmit('del',{id:this.listData[index].id})
      },
      submitAdd(url){
        let thi = this
        console.log(url)
        if (!url){
          thi.$message({
            message: '请上传完整信息！',
            type: 'error',
          });
          return
        }
        thi.mySubmit('add', {url}).then(function (code) {
          if (code==200) {
            thi.addVisible = false
            thi.getStart()
          }
        })
      },

    }
  }
</script>

<style scoped>
  .admin-body{
    /*background-color: white;*/
    width: 100%;
  }
  .main{
    background-color: white;
    min-height: 500px;
    padding: 10px;
    margin: 15px;
    border: #EDEDED 1px solid;
    border-radius: 5px;
  }

</style>
